/* Here is an example of openlog, syslog and closelog
 * This example sets the logmask so that debug and informational messages
 * get discarded without ever reaching syslog. So the second syslog in the
 * example does nothing ...
 * Origin:
 * https://www.gnu.org/software/libc/manual/html_node/Syslog-Example.html
 *
 * Documents: man syslog, man setlogmask, man getuid
 *
 * Compile: gcc syslog.c
 * Run: ./a.out
 * Result: cat /var/log/syslog | grep exampleprog
 * See something like this:
 * Jun 30 11:57:00 dell exampleprog[4211]: Program started by User 1000
 *
 */
#include <unistd.h>
#include <syslog.h>
#include <sys/types.h>

int main(void)
{
	setlogmask(LOG_UPTO(LOG_NOTICE));
	openlog("exampleprog",LOG_CONS | LOG_PID |LOG_NDELAY, LOG_LOCAL1);

	syslog(LOG_NOTICE,"Program started by User %d",getuid());
	syslog(LOG_INFO,"A tree falls in a forest");

	closelog();
	return 0;
}
